{{--
/**
 * Created by PhpStrom
 * User: 郭碧云
 * Date: 2021/3/22 9:13
 * Desc:
 */
--}}
@extends("layout.admin")

@section("title", "分配权限")

@section("content")
    <style>
        .layui-tree-icon {
            height: 15px;
            line-height: 15px;
            width: 16px;
        }

        .layui-tree-icon .layui-icon {
            font-size: 17px;
        }

        .layui-input-block {
            margin-left: 139px;
        }

        .layui-form-checkbox span {
            font-weight: 550;
        }
        .layui-form-checkbox[lay-skin=primary] {
            height: 25px !important;
        }
    </style>

    <div class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">
        <form class="layui-form" method="post" action="{{ session('guard')=="admin"?route("admin.role.permission_assign", ['role_id' => $role_id]):route("system.role.permission_assign", ['role_id' => $role_id]) }}" id="per_form">
            @csrf
            <div class="layui-form-item" style="padding: 0px 39px;">分配角色：{{$role_name}}</div>
            @foreach($permissionGroups as $group)
                <div class="layui-form-item" id="test">
                    <label class="layui-form-label" style="width: 107px;font-weight: 550;"><span
                            class="layui-tree-iconClick layui-tree-icon"><i class="layui-icon layui-icon-addition"></i></span>{{$group['display_name']}}
                    </label>
                    <ul class="layui-input-block" style="margin-top: 10px ;">
                        @if(isset($group['children']))
                        @foreach($group['children'] as $permission)
                            <li class="layui-col-xs2" >
                                <input type="checkbox" name="permission[]" class="parent" lay-skin="primary"
                                       value="{{$permission['name']}}"

                                       @if($role_permission['error']==0) @foreach($role_permission['data'] as $p) @if($p['id']==$permission['id']) checked @endif @endforeach @endif

                                       title="{{$permission['display_name']}}">
                                <ul style="margin-left: 27px;display: none;">

                                    @if(isset($permission['children']))
                                    @foreach($permission['children'] as $controller)
                                        <input type="checkbox" name="permission[]" lay-skin="primary"
                                               value="{{$controller['name']}}"

                                               @if($role_permission['error']==0) @foreach($role_permission['data'] as $p) @if($p['id']==$controller['id']) checked @endif @endforeach @endif

                                               title="{{$controller['display_name']}}">
                                    @endforeach
                                    @endif


                                </ul>
                            </li>
                        @endforeach
                        @endif
                    </ul>
                </div>
            @endforeach
        </form>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-sm" id="sub">立即提交</button>
                <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick='window.location.href="javascript:history.go(-1)"'>返回</button>
            </div>
        </div>
    </div>

@endsection

@section("script")
    <script type="text/javascript">
        layui.use(['table', 'form', 'jquery'], function () {
            var form = layui.form,
                table = layui.table,
                $ = layui.jquery;

            $("#sub").click(function (){
                admin.send($("#per_form").attr("action"),$("#per_form").attr("method"),$("#per_form").serialize());
            });

            $(".layui-form-label").click(function () {//layui-icon-subtraction
                if ($(this).find("i").hasClass("layui-icon-addition")) {
                    $(this).find(".layui-icon").removeClass("layui-icon-addition");
                    $(this).find(".layui-icon").addClass("layui-icon-subtraction");
                    $(this).parent().find("ul li").removeClass("layui-col-xs2");
                    $(this).parent().find("ul li ul").css("display","block");

                }
                else{
                    $(this).find(".layui-icon").removeClass("layui-icon-subtraction");
                    $(this).find(".layui-icon").addClass("layui-icon-addition");
                    $(this).parent().find("ul li").addClass("layui-col-xs2");
                    $(this).parent().find("ul li ul").css("display","none");
                }

            });
        });

    </script>
@endsection
